#include "task_watchdog.h"

WatchDog    watchdog_event;
IDLE_QUEUE_MSG watchdog_queue[5];

static RAW_U16 watchdog_fsm_initial(WatchDog *me, STATE_EVENT *e);
static RAW_U16 watchdog_fsm_feed(WatchDog *me, STATE_EVENT *e);

static RAW_U16 watchdog_fsm_initial(WatchDog *me, STATE_EVENT *e)
{
    return STM_TRAN(watchdog_fsm_feed);
}

static RAW_U16 watchdog_fsm_feed(WatchDog *me, STATE_EVENT *e)
{
    RAW_U16 status = STM_RET_IGNORED;
    switch(e->sig)
    {
        case STM_ENTRY_SIG:
            event_tick_arm(&(me->evt), 20);    
            status = STM_RET_HANDLED;
        break;
        case STM_TIMEOUT_SIG:
            event_tick_arm(&(me->evt), 35);    
            watchdog_fram_wdt_feed();
            status = STM_RET_HANDLED;
        break;
        default:
            status = STM_RET_IGNORED;
        break;
    }
    return status;
}

void watchdog_task_init(void)
{
    FSM_CONSTRUCTOR(&watchdog_event.evt.super, (stm_state_handler)watchdog_fsm_initial);
    fsm_init(&watchdog_event.evt.super, 0);
}
